package org.tlipoca.smchannel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.genntii.smdomain.entity.Channel;

import java.util.ArrayList;

@Mapper
public interface ChannelMapper extends BaseMapper<Channel> {

    @Select("select * from Channel where appid = #{appid};")
    Channel selectChannelByAppId(Integer appid);

    @Select("select count(*) from Channel where id = #{id};")
    int channelExists(@Param("id") Long id);

    ArrayList<Channel> getChannelBatch(@Param("channelIds") ArrayList<Long> channelIds);

    @Select("select * from Channel")
    ArrayList<Channel> getChannelList();

    @Select("select * " +
            "from Channel.Channel " +
            "where channel_name like concat('%',#{keyword},'%') " +
            "limit #{pageNum}, #{pageSize}")
    ArrayList<Channel> search(@Param("keyword") String keyword,
                              @Param("pageNum") int pageNum,
                              @Param("pageSize") int pageSize);

    @Select("select count(*) " +
            "from Channel.Channel " +
            "where channel_name like concat('%',#{keyword},'%') ")
    long searchTotal(@Param("keyword") String keyword);
}
